from flaskr.server.FilterDataServer import *

class LoadServer:
    def __init__(self, session):
        self.session = session
    def get_load(self):
        if ('sheets' in self.session.keys()):
            sheets = self.session['sheets']
            return sheets
        return None

    def clear_load(self):
        sheets = []
        self.session['sheets'] = sheets
        filter_data_server = FilterDataServer(self.session)
        filter_data_server.clear_filter_container()

    def del_load(self, sheet_name):
        has_change = False
        sheets = self.get_load()

        for i in range(len(sheets)):
            if sheets[i]['showName'] == sheet_name:
                if 'database' in sheets[i].keys() and sheets[i]['database']:
                    removePkl(sheets[i]['md5'])

                filter_data_server = FilterDataServer(self.session)
                filter_data_server.remove_filter_container(sheet_name)

                #删除过滤后的数据的缓存文件
                if 'copy_md5' in sheets[i].keys():
                    removePkl(sheets[i]['copy_md5'])

                del sheets[i]

                self.session['sheets'] = sheets

                has_change = True
                break

        if has_change:
            return True

        else:
            return False
